import axios from 'axios';

//设置接口服务器地址
let host = null;
const api_server = localStorage.getItem('api_server');
if (api_server !== null) {
    host = JSON.parse(api_server).host;
}

const service = axios.create({
    // process.env.NODE_ENV === 'development' 来判断是否开发环境
    baseURL: host,
    //设置请求超时时间
    timeout: 2000
});

service.interceptors.request.use(
    config => {
        return config;
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

service.interceptors.response.use(
    response => {
        //console.log(response)
        if (response.status === 200) {
            return response.data;
        } else {
            return Promise.reject();
        }
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

export default service;
